class @ProfileRatedBooksView extends ScrollPagingView


    initialize: ->
        super
        @setElement("#main")
        @model.bind("change", @render)
        @render()

    events:
        "click .sorting a[data-sort-option]": "changeSortOption"  
        "click .view-type img[data-view-type]": "changeViewType"
        "click .best-books-content ul.star-rating li a" : "rate"

    changeViewType: (event) ->     
        event.preventDefault()
        Loading.Start()
        viewType =  $(event.target).data("view-type")
        @model.setStaticProperty("BookViewType", viewType)
        @model.set("Page", 1, {silent: true})
        @renewScrolling()
        @model.fetch()

    changeSortOption: (event) ->
        event.preventDefault()
        Loading.Start()
        column = $(event.target).data("sort-option")
        direction = $(event.target).data("sort-direction")
        @model.setStaticProperty("Column", column)
        @model.setStaticProperty("Direction", direction)
        @model.set("Page", 1, {silent: true})
        @renewScrolling()
        @model.fetch() 

     getTemplateUrl: ->      
        switch @model.get("BookViewType")
            when 0 then SiteMap.Profile.ListingIconViewTemplate
            when 1 then SiteMap.Profile.ListingListViewTemplate
            else ''
   
    rate: (e) ->
        e.preventDefault()

        rating = $(e.currentTarget)
        ul = rating.closest("ul.star-rating:not(.disabled)")

        if ul.length > 0
            ratingModel = new RatingModel()
            ratingModel.set(
                "BookId": ul.data("val-bookid")
                "RatingValue": rating.data("rate-value")
            )

            ratingView = new RatingView(
                model: ratingModel
                el: $(ul)
            )      

    afterLoad: (data) =>
        @GetTemplate(@getTemplateUrl(), (compiledTemplate) =>
            $(@el).find("ul.listing").append(compiledTemplate(Items:data))
        )

    render: ->
        @Navigate(@model.url(), false, true)

        @GetTemplate(SiteMap.Profile.RatedBooksTemplate, (compiledTemplate) =>
            $(@el).html(compiledTemplate(@model.toJSON()))
            @startLoading()
            @renewScrolling()
        )

    dispose: ->
        